package von.seiji.cn.test;

import cn.hutool.http.HttpUtil;
import net.coobird.thumbnailator.Thumbnails;
import org.junit.Test;
import von.seiji.cn.IpUtil;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @Author: Amasawa Seiji
 * @Since: 2021/1/1 17:24
 * @Description: 暂无描述
 */
public class T9 {

    @Test
    public void test1(){
        String s = HttpUtil.get("http://ip.ws.126.net/ipquery?ip=");
        System.out.println(s);
    }

    @Test
    public void test2(){
        long l = HttpUtil.downloadFile("https://demo.easyweb.vip/spa/components/system/login-record.html"
                , "F://login-record.html");
        System.out.println("l = " + l);
        HashMap addresses =
                IpUtil.getAddresses("127.0.0.1");
        System.out.println(addresses);
    }

    @Test
    public void test() {
        String str="ads/\\\\56756\\/d/\\/f/\\s\\\\d/////\\f/\\s/f\\/s/fs";
        System.out.println(str.replaceAll("/+", "\\\\").replaceAll("\\\\(\\\\)+", "\\\\"));
    }

    @Test
    public void test40() throws IOException {
        FileInputStream inputStream = new FileInputStream("C:\\Users\\Administrator\\Desktop\\临时储物库\\图片2\\图片2\\suspect\\xianyif2-1.jpg");
        FileOutputStream out = new FileOutputStream(new File("F://1.jpg"));
        FileOutputStream stream = new FileOutputStream("");
        Thumbnails.of(inputStream)
                .scale(0.1f)
                .outputQuality(1.0f)
                .toOutputStream(stream);

   /*     byte[] bytes = outputStream.toByteArray();
        final ByteArrayInputStream swapStream = new ByteArrayInputStream(bytes);
        BufferedImage read = ImageIO.read(swapStream);*/

       /* swapStream.close();
        inputStream.close();
        outputStream.close();*/
        System.out.println("完成");
    }

    @Test
    public void test57() {

//        Webcam webcam = Webcam.getDefault();
            //实现拍照保存-------start
            String fileName = "D://LL/" + System.currentTimeMillis();       //保存路径即图片名称（不用加后缀）
//        new Thread(() -> WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG)).start();

            TimerTask task = new TimerTask() {
                @Override
                public void run() {
                    // 要执行的代码
                    System.err.println("尝试捕获图片！！！");
//                WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG);
                }
            };

            Timer timer = new Timer();
            timer.schedule(task, 2000, 1000);

    }

}
